package com.topscomm.pm.script;

import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.pm.PmScript;
import com.topscomm.pm.pojo.PmProjectEntity;
import com.topscomm.pm.pojo.PmStartApplyEntity;
import com.topscomm.pm.service.impl.PmProjectService;
import com.topscomm.pm.service.impl.PmStartApplyService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;

import java.util.Date;

public class PmStartScript extends PmScript {
    /**
     * @author: wushenghong
     * @date: 2020/6/4
     * @description: 更新项目档案
     */
    public void updateProject(ITapService service, TapEntity entity) throws Exception {
        // 审批节点实例
        CboApprovalNodeInsEntity nodeIns = (CboApprovalNodeInsEntity) entity;
        String sourceId = ConvertUtil.convertToString(nodeIns.getSourceid());
        PmProjectService pmProjectService = (PmProjectService) SpringUtil.getBean("pmProjectService");
        PmStartApplyService pmStartApplyService = (PmStartApplyService) SpringUtil.getBean("pmStartApplyService");
        PmStartApplyEntity pmStartApplyEntity = pmStartApplyService.queryById(sourceId);
        if (pmStartApplyEntity != null) {
            Date actualStartTime = pmStartApplyEntity.getStarttime();//开工时间
            PmProjectEntity pmProjectEntity = pmProjectService.queryById(ConvertUtil.convertToString(pmStartApplyEntity.getProjectid()));
            if (pmProjectEntity != null) {
                // 更新项目开工时间
                pmProjectEntity.setActualstarttime(actualStartTime);
                pmProjectEntity.setProjectstate(2);//将项目状态置为执行中
                pmProjectService.updateEntity(pmProjectEntity);
            }
        }
    }
}
